
/**    
 * <p>Copyright： 东软烟草产品研发团队</p>   
 */

package com.jkl.service.role;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jkl.dao.role.BsRoleMapper;
import com.jkl.entity.role.BsRole;
import com.jkl.service.role.inter.BsRoleServiceInterface;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 123service
 * <p>
 * <p>
 * 123service
 * <p>
 * <p>
 * 变更说明：lin.pf 2018年1月17日 123service
 * <p>
 * Date:2018年10月01日
 * 
 * @author lin.pf
 * @version 1.0
 */
@Service
@Slf4j
public class BsRoleService implements BsRoleServiceInterface {

	@Autowired
	private BsRoleMapper bsRoleMapper;

	@Override
	public PageInfo<BsRole> findRoleByParam(BsRole params) {
		PageHelper.startPage(params.getCurrentPage(), params.getPageSize());
		return new PageInfo<>(bsRoleMapper.findRoleByParam(params));
	}

	@Override
	public void updateRoleByParam(BsRole params) {
		bsRoleMapper.updateByPrimaryKey(params);
	}

	@Override
	public void updateMenuByParam(BsRole params) {
		bsRoleMapper.deleteRoleMenuByRoleId(params.getRowId());
		int rowId = bsRoleMapper.getRoleMenuLastId();
		int roleId = params.getRowId();
		for (Integer menuId : params.getMenuIds()) {
			rowId++;
			bsRoleMapper.addRoleMenuBYRoleId(rowId, roleId, menuId);
		}
	}

	@Override
	public void addRole(BsRole bsRole) {
		bsRoleMapper.insert(bsRole);
	}
}